package com.collect.collect.api.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.collect.collect.api.dao.DataMonitorMapper;
import com.collect.collect.api.entity.DataMonitor;
import com.collect.collect.api.service.ISlaveService;
import com.collect.collect.config.annotation.DataSource;
import com.collect.collect.config.enums.DataSourceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DataSource(DataSourceType.SLAVE)
public class SlaveServiceImpl extends ServiceImpl<DataMonitorMapper, DataMonitor> implements ISlaveService {

    @Autowired
    private DataMonitorMapper dataMonitorMapper;


    @Override
    public List<DataMonitor> getDataMonitorList10() {
        Page<DataMonitor> page = new Page<>(1,10);
        page = page(page, Wrappers.<DataMonitor>lambdaQuery());
        List<DataMonitor> dataMonitorList = page.getRecords();
        return dataMonitorList;
    }

    @Override
    public boolean updateAddCounter(String monitorId, int counter) {
        counter += 1;
        return update(Wrappers.<DataMonitor>lambdaUpdate()
                .set(DataMonitor::getCounter,counter)
                .eq(DataMonitor::getMonitorId,monitorId));
    }

    @Override
    public boolean delete(String monitorId) {
        return remove(Wrappers.<DataMonitor>lambdaQuery().eq(DataMonitor::getMonitorId,monitorId));
    }
}
